<script>
export default {
  name: "index",
  data(){
    return {
      afterSalesList:[],
      total:0,
      queryCondition:{
        pageNum:1,
        pageSize:10,
      }
    }
  },
  methods:{
    getList(){
      const userInfo = uni.getStorageSync('userInfo');
      // console.log(userInfo)
      // console.log(userInfo.id)
      this.queryCondition.userId =  userInfo.id;
      uni.request({
        url: 'http://localhost:8080/app/shop/after_sales_requests/list',
        method: 'GET',
        data:this.queryCondition,
        success: (res) => {
          if (res.statusCode === 200) {
            console.log(res.data.rows)
            this.afterSalesList=this.afterSalesList.concat(res.data.rows);
            this.total = res.data.total;
          } else {
            uni.showToast({ title: '加载失败', icon: 'none' });
          }
        },
        fail: (err) => {
          uni.showToast({ title: '网络错误', icon: 'none' });
        }
      });
    }
  },
  created() {
    this.getList();
  },
  onReachBottom(){
    this.queryCondition.pageNum++;
    this.getList();
  }
}
</script>

<template>
  <view>
    <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
                 @scrolltolower="lower" @scroll="scroll">
       <view
           v-for="(item, goodsIndex) in afterSalesList" :key="goodsIndex"
       >
         <view class="item">
           <view class="item-row">
             <text class="label">订单号：</text>
             <text class="value">{{ item.orderId }}</text>
           </view>
           <view class="item-row">
             <text class="label">售后理由：</text>
             <text class="value">{{ item.requestReason }}</text>
           </view>
           <view class="item-row">
             <text class="label">创建时间：</text>
             <text class="value">{{ item.createTime }}</text>
           </view>
           <view class="item-row">
             <text class="label">售后类型：</text>
             <text class="value" v-if="item.requestType == 'refund'">退款</text>
             <text class="value" v-if="item.requestType == 'exchange'">换货</text>
           </view>
           <view class="item-row">
             <text class="label">售后状态：</text>
             <text class="value" v-if="item.requestStatus == 'rejected'">拒绝</text>
             <text class="value" v-if="item.requestStatus == 'pending'">待审核</text>
             <text class="value" v-if="item.requestStatus == 'approved'">通过</text>
           </view>
         </view>

<!--         <view>订单号 : {{ item.orderId }}</view>-->
<!--         <view>售后理由 : {{ item.requestReason }}</view>-->
<!--         <view>  </view>-->

<!--         <image class="goods-img" :src="goodsItem.image" mode="aspectFill"></image>-->
       </view>
    </scroll-view>
  </view>
</template>

<style scoped lang="scss">
.item {
  padding: 15px;
  border-bottom: 1px solid #eee;
  background-color: #fff;
}

.item-row {
  display: flex;
  margin-bottom: 10px;
}

.item-row:last-child {
  margin-bottom: 0;
}

.label {
  font-weight: bold;
  width: 80px;
  color: #333;
}

.value {
  flex: 1;
  color: #666;
}
</style>